<!--
 * @Author: gaotang
 * @Date: 2025年01月03日
 * @Email: qq23745038@126.com
 * @LastEditors: gaotang
 * @LastEditTime: 2025-01-03 18:54:52
-->
<template>
  <Echart v-if="pageflag" :options="options" class="left_center_inner" ref="charts" height="300px" />
  <Reacquire v-else @onclick="getData" style="line-height: 300px">
    重新获取
  </Reacquire>
</template>

<script>
import { colorsA, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';

export default {
  name: 'ARightRightTop',
  data() {
    return {
      options: {},
      countUserNumData: {
        axisData: ['10月', '11月', '12月', '1月'],
        seriesData: [25, 98, 55, 98],
        seriesData1: [35, 48, 75, 28],
        seriesDataBg: [40, 70, 30, 20],
      },
      pageflag: true,
      timer: null,
      chartType: 0,
      autoTimer: null,
      series: [],
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    autoChange() {
      this.options.series = this.chartType >= 2 ? this.series : this.series.slice(0, this.chartType + 1);
      if (this.chartType > 2) {
        this.chartType = 0;
      } else {
        this.chartType += 1;
      }
    },
    autoSwitper() {
      if (this.autoTimer) {
        return;
      }
      let looper = (a) => {
        this.autoChange();
      };
      this.autoTimer = setInterval(
        looper,
        3000
      );
    },
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;
      this.init(this.countUserNumData);

      this.autoSwitper();
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
      );
      let myChart = this.$refs.charts.chart;
      myChart.on('mouseover', (params) => {
        this.clearData();
      });
      myChart.on('mouseout', (params) => {
        this.timer = setInterval(
          looper,
          2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
        );
      });
    },
    init(currentData) {
      let axisData = currentData.axisData;
      let seriesData = [
        [...currentData.seriesData],
        [...currentData.seriesData1],
        [...currentData.seriesDataBg],
      ];
      const options = {
        grid: {
          top: '12%',
          left: '4%',
          right: '4%',
          bottom: '15%',
          containLabel: true,
        },
        legend: {
          show: true,
          top: '0%',
          right: '4%',
          icon: 'rect',
          itemWidth: 12,
          itemHeight: 6,
          itemGap: 10,
          textStyle: legend.textStyle,
          data: ['加油站', '加油机', '从业人员'],
        },
        xAxis: {
          type: 'category',
          data: axisData,
          // boundaryGap: false,
          // boundaryGap: true,
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false, // 不显示下切线
          },
          axisLabel: xAxis.axisLabel,
          axisLine: {
            lineStyle: {
              background: 'rgba(176, 215, 255, 0.4)',
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            // max: 8000,
            // min: 100,//
            // interval: 2000,
            axisLabel: yAxis.axisLabel,
            axisLine: {
              show: false,
              // interval: 1,
              lineStyle: {
                color: 'rgba(0,0,0,0.5)',
              },
            },
            splitLine: {
              show: true,
              // interval: 1,
              lineStyle: {
                color: ['rgba(176, 215, 255, 0.2)'],
                width: 1,
                type: 'dashed',
              },
            },
            // splitLine: {
            //   show: false,
            // },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [],
      };
      const series = [
        {
          name: '加油站',
          type: 'bar',
          barWidth: 10,
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: false,
          showSymbol: true,
          data: seriesData[0],
          itemStyle: {
            normal: {
              // color: "#38FFBA",
              // color: 'rgba(0,219,254, .7)',
              color: {
                type: 'linear',
                x: 0,
                y: 2,
                x2: 0,
                y2: 0,
                colorStops: [
                  {
                    offset: 0,
                    color: '#1890FF',
                  },
                  {
                    offset: 1,
                    color: '#1EE7E7',
                  },

                ],
                globalCoord: false,
              },
            },
          },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
          },
        },
        {
          name: '加油机',
          type: 'bar',
          barWidth: 10,
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: false,
          showSymbol: true,
          itemStyle: {
            normal: {
              // color: "#38FFBA",
              // color: 'rgba(0,219,254, .7)',
              color: {
                type: 'linear',
                x: 0,
                y: 2,
                x2: 0,
                y2: 0,
                colorStops: [
                  {
                    offset: 0,
                    color: '#1EE7E7',
                  },
                  {
                    offset: 1,
                    color: '#1890FF',
                  },

                ],
                globalCoord: false,
              },
            },
          },
          data: seriesData[1],
          lineStyle: {
            normal: {
              width: 2,
            },
          },
        },
        {
          name: '从业人员',
          type: 'bar',
          barWidth: 10,
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: false,
          showSymbol: true,
          // itemStyle: {
          //   normal: {
          //     color: '#F28902',
          //     // color: 'rgba(0,219,254, .7)',
          //   },
          // },
          itemStyle: {
            normal: {
              // color: "#38FFBA",
              // color: 'rgba(0,219,254, .7)',
              color: {
                type: 'linear',
                x: 0,
                y: 2,
                x2: 0,
                y2: 0,
                colorStops: [
                  {
                    offset: 0,
                    color: '#FF950E',
                  },
                  {
                    offset: 1,
                    color: '#C8FC03',
                  },

                ],
                globalCoord: false,
              },
            },
          },
          data: seriesData[2],
          lineStyle: {
            normal: {
              width: 2,
            },
          },
        },
      ];
      options.series = series;
      this.series = [...series];
      this.options = options;
    },
    chartClick(params) {
      // 这里处理你的点击逻辑
      this.$emit('chartClick', params);
    },
  },
};
</script>
<style lang="scss" scoped></style>
